package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.AssetReturnQueryDto;
import com.group.eams.pojo.dto.FixedAssetDetailQueryDto;
import com.group.eams.pojo.entity.AssetReturn;
import com.group.eams.pojo.vo.AssetReturnListVo;
import com.group.eams.pojo.vo.FixedAssetDetailListVo;
import com.group.eams.service.AssetReturnService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 资产归还表(AssetReturn)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/assetReturn")
@ResponseBody
public class AssetReturnController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetReturnService assetReturnService;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "资产归还列表")
    public Result List(AssetReturnQueryDto assetReturnQueryDto){
        Page<AssetReturnListVo> listVoPage = assetReturnService.findAssetReturnList(assetReturnQueryDto);

        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/find",method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询资产归还信息")
    public Result find(@RequestParam Long id){
        AssetReturn assetReturn = assetReturnService.getById(id);
        return Result.buildSuccess(assetReturn);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加资产归还信息")
    public Result add(@RequestBody AssetReturn assetReturn){
        boolean result = assetReturnService.save(assetReturn);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "修改资产归还信息")
    public Result update(@RequestBody AssetReturn assetReturn){
        boolean result = assetReturnService.updateById(assetReturn);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @ApiOperation(value = "删除资产归还信息")
    public Result add(@RequestParam Long id){
        boolean result = assetReturnService.removeById(id);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有资产归还信息")
    public Result findAll(){
        List<AssetReturn> assetReturnList = assetReturnService.list();
        return Result.buildSuccess(assetReturnList);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    @ApiOperation(value = "批量删除资产归还信息")
    public Result batchRemove(@RequestBody BatchDeleteDto batchDeleteDto){
        boolean result = assetReturnService.removeByIds(batchDeleteDto.getIds());
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }


    @RequestMapping(value = "/findByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据申请编号查询资产借用信息")
    public Result findByApplicationNum(@RequestParam String applicationNum){
        AssetReturn assetReturn = assetReturnService.findByApplicationNum(applicationNum);
        return Result.buildSuccess(assetReturn);
    }

    @RequestMapping(value = "/assetDetail",method = RequestMethod.GET)
    @ApiOperation(value = "资产借用明细")
    public Result assetList(FixedAssetDetailQueryDto fixedAssetDetailQueryDto){
        Page<FixedAssetDetailListVo> listVoPage = assetReturnService.findByQueryDto(fixedAssetDetailQueryDto);
        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量添加资产归还信息")
    public Result addBatch(@RequestBody List<AssetReturn> assetReturnList){
        boolean result = assetReturnService.saveBatch(assetReturnList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量修改资产归还信息")
    public Result updateBatch(@RequestBody List<AssetReturn> assetReturnList){
        boolean result = assetReturnService.updateBatchById(assetReturnList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/deleteByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据单号删除资产归还信息")
    public Result deleteByApplicationNum(@RequestParam String applicationNum){
        int result = assetReturnService.deleteByApplicationNum(applicationNum);
        return result>0?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    
}

